<template>
  <!-- 品牌详情-关联直播 88/90-->
  <div id="associatedVideo">
    <div class="vip_pay_box" v-if="!vipRootObj[88][90].owner">
      <div class="vip_bg_box">
        <div class="vip_bg_mask"></div>
      </div>
      <div class="vip_box_wrap">
        <payVip
          routerName="FansPortrait"
          :lowestVipNum="vipRootObj[88][90].ownerMinLevel"
        />
      </div>
    </div>
    <template v-else>
      <div class="top">
        <radio_group01
          :radio_values="['近7天', '30天', '90天']"
          v-model="KindName"
          class="tab01"
        />
        <div class="optionsBox">
          <el-date-picker
            class="long_time"
            v-model="liveTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            prefix-icon="el-icon-arrow-down"
            unlink-panels
            :clearable="false"
            :picker-options="pickeroptions"
            value-format="yyyy-MM-dd"
            @change="onPick1"
          ></el-date-picker>
        </div>
      </div>
      <div class="header">
        <div class="line"></div>
        <span>关联直播数据</span>
      </div>
      <div class="video_Data">
        <div class="video_box">
          <p>直播总销量</p>
          <p>{{ format_num(volume) }}</p>
        </div>
        <div class="video_box">
          <p>直播总销售额</p>
          <p>{{ format_num(amount) }}</p>
        </div>
      </div>
      <div class="header">
        <div class="line"></div>
        <span>直播列表</span>
      </div>

      <section>
        <table class="table">
          <thead>
            <tr>
              <!-- <th>视频内容</th> -->
              <th>直播间</th>
              <th>达人</th>
              <th
                @click="sort_fun(true, 1)"
                v-if="orderType == '0' && sort == 1"
              >
                开播时间
                <img src="@/assets/meng/down_up.png" />
              </th>
              <th v-else @click="sort_fun(false, 1)">
                开播时间
                <img
                  src="@/assets/meng/up_down.png"
                  v-if="orderType == '1' && sort == 1"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>

              <th
                @click="sort_fun(true, 2)"
                v-if="orderType == '0' && sort == 2"
              >
                关联品牌商品数
                <img src="@/assets/meng/down_up.png" />
              </th>
              <th v-else @click="sort_fun(false, 2)">
                关联品牌商品数
                <img
                  src="@/assets/meng/up_down.png"
                  v-if="orderType == '1' && sort == 2"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>
              <th
                @click="sort_fun(true, 3)"
                v-if="orderType == '0' && sort == 3"
              >
                关联商品直播销量
                <img src="@/assets/meng/down_up.png" />
              </th>
              <th v-else @click="sort_fun(false, 3)">
                关联商品直播销量
                <img
                  src="@/assets/meng/up_down.png"
                  v-if="orderType == '1' && sort == 3"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>

              <th
                @click="sort_fun(true, 0)"
                v-if="orderType == '0' && sort == 0"
              >
                关联商品直播销售额
                <img src="@/assets/meng/down_up.png" />
              </th>
              <th v-else @click="sort_fun(false, 0)">
                关联商品直播销售额
                <img
                  src="@/assets/meng/up_down.png"
                  v-if="orderType == '1' && sort == 0"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>
            </tr>
          </thead>

          <tbody>
            <tr v-for="(item, i) in list" :key="i + 'i'">
              <td>
                <div class="goodsBox">
                  <div class="leftBox">
                    <img
                      @click="livedetails(item.status, item.roomId)"
                      :src="item.roomLogo"
                      class="leftImg"
                      v-errorImg:live
                    />

                    <div class="livingGif1" v-if="item.status == 1">
                      <p class="livingGif">
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                      </p>
                    </div>
                  </div>

                  <div class="rightBox">
                    <div>
                      <p
                        class="overflowTextWl"
                        @click="livedetails(item.status, item.roomId)"
                      >
                        {{ item.roomTitle }}
                      </p>
                    </div>
                    <div class="rightBox-1">
                      <p>
                        开播时长:{{
                          format_time((item.endUnix - item.beginUnix) * 1000)
                        }}
                      </p>
                    </div>
                  </div>
                </div>
              </td>
              <td>
                <div>
                  <img
                    :src="item.logo"
                    alt=""
                    @click="talentdetails(item.authorId)"
                  />
                  <p class="title" @click="talentdetails(item.authorId)">
                    {{ item.nickName }}
                  </p>
                </div>
              </td>
              <td>{{ item.beginTime }}</td>
              <td>{{ format_num(item.liveproduct) }}</td>
              <td>{{ format_num(item.livevolume) }}</td>
              <td>{{ format_num(item.livesales) }}</td>
            </tr>
          </tbody>
        </table>
        <div
          v-loading="loading"
          v-if="loading"
          class="loading"
          element-loading-text="拼命加载中..."
          element-loading-spinner="el-icon-loading"
        ></div>
        <div class="pageBox" v-if="list.length != 0 && !loading">
          <el-pagination
            background
            layout="prev, pager, next, jumper"
            :total="pageTotal"
            :page-size="30"
            :current-page="page"
            @current-change="livelist"
            :hide-on-single-page="true"
          ></el-pagination>
        </div>
        <div class="empty addTop" v-show="!loading && list.length == 0">
          <img src="@/assets/liu/zw.png" />
          <p>暂无数据</p>
        </div>
      </section>
    </template>
  </div>
</template>

<script>
export default {
  data() {
    return {
      sort: 0,
      page: 1,
      pageTotal: 0,
      orderType: "0", //desc倒序  asc升序
      loading: true,
      loading1: true,
      list: [],
      KindName: "30天",
      startDate: "",
      endDate: "",
      liveTime: [],
      // 选择时间 不可选的日期
      pickeroptions: {
        disabledDate: (time) => {
          return (
            time.getTime() < Date.now() - 90 * 24 * 60 * 60 * 1000 ||
            time.getTime() > Date.now()
          ); // 返回 所有时间 大于 当前时间
        },
      },
      vipRootObj: this.$store.state.userRoot, //会员权限对象
      volume: 0,
      amount: 0,
    };
  },
  components: {},
  computed: {},
  watch: {
    KindName: function (newVal, oldVal) {
      if (newVal) {
        this.page = 1;
        this.list = [];
        this.livelist();
      }
    },
    // changeData() {},
  },
  created() {
    if (this.vipRootObj[88][90].owner) {
      this.livelist();
    }
  },
  methods: {
    // 跳转
    livedetails(status, id) {
      if (status == 1) {
        let router = this.$router.resolve({
          path: `/live/${id}`,
        });
        window.open(router.href, "_blank");
      } else {
        let router = this.$router.resolve({
          path: `/talent_main/liveDetailsRoot/${id}/0`,
        });
        window.open(router.href, "_blank");
      }
    },
    // 跳转
    talentdetails(id) {
      let router = this.$router.resolve({
        path: `/talent_main/tdetails/${id}/0`,
      });
      window.open(router.href, "_blank");
    },

    // 排序
    sort_fun(parm01, parm02) {
      if (parm01) {
        this.orderType = "1";
      } else {
        this.orderType = "0";
      }
      this.sort = parm02;
      this.page = 1;
      this.list = [];
      this.livelist();
    },
    onPick1() {
      this.KindName = "";
      this.list = [];
      this.page = 1;
      this.livelist();
    },

    livelist(i) {
      this.list = [];
      if (i) {
        this.page = i;
        this.backTop();
      }
      this.loading = true;
      switch (this.KindName) {
        case "近7天":
          this.endDate = this.timestamp(Date.now() / 1000 - 86400 * 1, "Y-M-D");
          this.startDate = this.timestamp(
            Date.now() / 1000 - 86400 * 7,
            "Y-M-D"
          );
          break;
        case "30天":
          this.endDate = this.timestamp(Date.now() / 1000 - 86400 * 1, "Y-M-D");
          this.startDate = this.timestamp(
            Date.now() / 1000 - 86400 * 30,
            "Y-M-D"
          );

          break;

        case "90天":
          this.endDate = this.timestamp(Date.now() / 1000 - 86400 * 1, "Y-M-D");
          this.startDate = this.timestamp(
            Date.now() / 1000 - 86400 * 90,
            "Y-M-D"
          );
          break;
        default:
          this.startDate = this.liveTime[0];
          this.endDate = this.liveTime[1];
          break;
      }
      this.liveTime = [this.startDate, this.endDate];
      this.$axios
        .post("/api/Brand/BrandRelLive", {
          // brandId: "f91858aaa7a1e67428a99f45f19be654",
          brandId: this.$route.query.id,
          startdate: this.startDate,
          enddate: this.endDate,
          page: this.page,
          size: 30,
          sort: this.sort,
          order_by: this.orderType,
        })
        .then((res) => {
          this.loading = false;
          if (res.data.code == 0) {
            this.list = res.data.data.livelist;
            this.amount = res.data.data.liveSumAmount;
            this.volume = res.data.data.liveSumVolume;
            this.pageTotal = res.data.count;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    backTop() {
      document.body.scrollTop = document.documentElement.scrollTop = 0;
    },
  },
};
</script>

<style lang="less" scoped>
#associatedVideo {
  height: 83vh;
  overflow: auto;
  background-color: #fff;
  border-radius: 6px;
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
  letter-spacing: 1px;
  padding-bottom: 14px;
  position: relative;
  .loading {
    // position: absolute;
    // left: 300px;
  }
  .loading1 {
    border: none;
  }
  .livingGif {
    position: absolute;
    left: 1px;
    bottom: 10px;
    font-size: 12px;
    width: 13px;
    height: 12px;
  }
  .livingGif1 {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    line-height: 22px;
    line-height: 30px;
    color: #ffffff;
    background-image: linear-gradient(90deg, #ff295d 1%, #fa4fa2),
      linear-gradient(#fff, #fff);
    overflow: hidden;
  }

  .top {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
    .tab01 {
      margin-right: 20px;
    }
  }

  .header {
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0px;
    color: #222222;

    span {
      display: inline-block;
      line-height: 28px;
    }
    .line {
      width: 4px;
      height: 16px;
      border-radius: 100px;
      margin-right: 6px;
      background-color: #fd7f2c;
    }
  }
  .video_Data {
    display: flex;
    margin: 20px 0 40px 0;
    .video_box {
      width: 354px;
      height: 50px;
      background-color: #f5f5f5;
      border-radius: 6px;
      margin-right: 20px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      p:nth-child(1) {
        font-size: 14px;
        font-weight: normal;
        color: #888888;
      }
      p:nth-child(2) {
        font-size: 18px;
        font-weight: 600;
        color: #222222;
      }
    }
  }
  table {
    overflow-x: auto;
    margin-top: 20px;
    width: 100%;
    thead {
      tr {
        width: 100%;
        position: relative;
        th {
          cursor: pointer;
          img {
            width: 5px;
            height: 10px;
            vertical-align: 0;
          }
        }
        th:nth-of-type(1),
        th:nth-of-type(2) {
          text-align: left;
          padding-left: 37px;
        }
        th:nth-of-type(2) {
          padding-left: 15px;
        }
      }
    }
    tbody {
      tr {
        height: 78px;
        text-align: center;
        td:nth-of-type(2),
        td:nth-of-type(3),
        td:nth-of-type(4),
        td:nth-of-type(5),
        td:nth-of-type(6),
        td:nth-of-type(7) {
          font-family: DINAlternate-Bold;
          font-size: 15px;
          color: #222222;
        }
        td:nth-of-type(2) {
          width: 150px;
          div {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            p {
              width: 150px !important;
              text-align: left;
            }
            img {
              width: 50px;
              height: 50px;
              border-radius: 50%;
              margin-right: 10px;
              cursor: pointer;
            }
          }
        }
        td:nth-of-type(3) {
          width: 15%;
        }
        td:nth-of-type(1) {
          width: 26%;
          .overflowTextWl {
            cursor: pointer;
            width: 150px !important;
            overflow: hidden;
            text-align: center;
          }

          font-size: 14px;
        }
      }
      // 商品
      .goodsBox {
        position: relative;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-left: 29px;
        .leftBox {
          width: 50px;
          height: 50px;
          position: relative;
        }
        .leftImg {
          cursor: pointer;
          width: 50px;
          height: 50px;
          border-radius: 6px;
          object-fit: cover;
        }
        .rightBox {
          flex: 1;
          text-align: left;
          margin-left: 10px;
          div:nth-of-type(1) {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            text-align: left;

            p {
              width: 400px;
              font-weight: 600;
              font-size: 14px;
              font-stretch: normal;
              letter-spacing: 0px;
              color: #222222;
              text-align: left;
            }
            .overflowTextWl:hover {
              color: #fd7f2c;
            }
          }
          .rightBox-1 {
            p {
              font-size: 13px;
              color: #888;
              margin-top: 4px;
              white-space: nowrap;
            }
          }
          .menu {
            width: 10px;
            height: 6px;
            margin-top: 12px;
          }
        }
      }
    }
    .title {
      cursor: pointer;
      font-size: 14px;
      font-weight: 600;
      color: #222;
      width: 151px;
      height: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .title:hover {
      color: #fd7f2c;
    }
    .num {
      padding-top: 6px;
    }
    img {
      width: 16px;
      margin-right: 3px;
      vertical-align: -2px;
    }
  }
  .addTop {
    // margin-top: 100px;
    border: none;
  }
}
</style>
